From fce5e6b8c68024ce4402d1325b976b856e6dd41f Mon Sep 17 00:00:00 2001 From: oliskoli Date: Wed, 3 May 2006 23:37:38 +0000 Subject: [PATCH] Add CET-functionality to format-specific data. --- gpsbabel/an1.c | 3 +++ gpsbabel/cet_util.c | 13 ++++++++++--- gpsbabel/cet_util.h | 3 +++ gpsbabel/defs.h | 3 +++ gpsbabel/garmin_fs.c | 1 + gpsbabel/ozi.c | 1 + gpsbabel/xmltag.c | 27 ++++++++++++++++++++++++++- 7 files changed, 47 insertions(+), 4 deletions(-) diff --git a/gpsbabel/an1.c b/gpsbabel/an1.c index c56806698..801de4d72 100644 --- a/gpsbabel/an1.c +++ b/gpsbabel/an1.c @@ -314,6 +314,7 @@ static an1_waypoint_record *Alloc_AN1_Waypoint( ) { result->fs.type = FS_AN1W; result->fs.copy = Copy_AN1_Waypoint; result->fs.destroy = Destroy_AN1_Waypoint; + result->fs.convert = NULL; return result; } @@ -336,6 +337,7 @@ static an1_vertex_record *Alloc_AN1_Vertex() { result->fs.type = FS_AN1V; result->fs.copy = Copy_AN1_Vertex; result->fs.destroy = Destroy_AN1_Vertex; + result->fs.convert = NULL; return result; } @@ -362,6 +364,7 @@ static an1_line_record *Alloc_AN1_Line( ) { result->fs.type = FS_AN1L; result->fs.copy = Copy_AN1_Line; result->fs.destroy = Destroy_AN1_Line; + result->fs.convert = NULL; return result; } diff --git a/gpsbabel/cet_util.c b/gpsbabel/cet_util.c index 1a50afbc6..08d021e54 100644 --- a/gpsbabel/cet_util.c +++ b/gpsbabel/cet_util.c @@ -947,6 +947,7 @@ static void cet_convert_waypt(const waypoint *wpt) { waypoint *w = (waypoint *)wpt; + format_specific_data *fs; if ((cet_output == 0) && (w->wpt_flags.cet_converted != 0)) return; @@ -957,6 +958,14 @@ cet_convert_waypt(const waypoint *wpt) w->notes = cet_convert_string(wpt->notes); w->url = cet_convert_string(wpt->url); w->url_link_text = cet_convert_string(wpt->url_link_text); + + fs = wpt->fs; + while (fs != NULL) + { + if (fs->convert != NULL) + fs->convert(fs); + fs = fs->next; + } } /* cet_convert_route_hdr: internal used within cet_convert_strings process */ @@ -993,8 +1002,6 @@ cet_convert_strings(const cet_cs_vec_t *source, const cet_cs_vec_t *target, cons { char *cs_name_from, *cs_name_to; -// printf("cet_convert_strings: enter\n"); fflush(stdout); - converter = NULL; if ((source == NULL) || (source == &cet_cs_vec_utf8)) @@ -1022,7 +1029,7 @@ cet_convert_strings(const cet_cs_vec_t *source, const cet_cs_vec_t *target, cons waypt_disp_all(cet_convert_waypt); route_disp_all(cet_convert_route_hdr, cet_convert_route_tlr, cet_convert_waypt); track_disp_all(cet_convert_route_hdr, cet_convert_route_tlr, cet_convert_waypt); - + cet_output = 0; if (global_opts.debug_level > 0) diff --git a/gpsbabel/cet_util.h b/gpsbabel/cet_util.h index b3ce840a8..84754ca45 100644 --- a/gpsbabel/cet_util.h +++ b/gpsbabel/cet_util.h @@ -102,6 +102,9 @@ int cet_valid_char(const char *src, const cet_cs_vec_t *vec); int cet_vfprintf(FILE *stream, const cet_cs_vec_t *src_vec, const char *fmt, va_list args); int cet_fprintf(FILE *stream, const cet_cs_vec_t *src_vec, const char *fmt, ...); +/* cet_convert_string: !!! ONLY VALID WITHIN 'cet_convert_strings' process !!! */ +char *cet_convert_string(char *str); + /* gpsbabel extensions */ void cet_convert_init(const char *cs_name, const int force); diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 170f3edf7..9e0d0aed4 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -207,12 +207,15 @@ typedef struct xml_tag { typedef void (*fs_destroy)(void *); typedef void (*fs_copy)(void **, void *); +typedef void (*fs_convert)(void *); + typedef struct format_specific_data { long type; struct format_specific_data *next; fs_destroy destroy; fs_copy copy; + fs_convert convert; } format_specific_data; format_specific_data *fs_chain_copy( format_specific_data *source ); diff --git a/gpsbabel/garmin_fs.c b/gpsbabel/garmin_fs.c index 91858f3df..e409982bc 100644 --- a/gpsbabel/garmin_fs.c +++ b/gpsbabel/garmin_fs.c @@ -36,6 +36,7 @@ garmin_fs_alloc(const int protocol) result->fs.type = FS_GMSD; result->fs.copy = (fs_copy) garmin_fs_copy; result->fs.destroy = garmin_fs_destroy; + result->fs.convert = NULL; result->fs.next = NULL; result->protocol = protocol; diff --git a/gpsbabel/ozi.c b/gpsbabel/ozi.c index b72d44beb..985b34250 100644 --- a/gpsbabel/ozi.c +++ b/gpsbabel/ozi.c @@ -100,6 +100,7 @@ ozi_alloc_fsdata(void) fsdata->fs.type = FS_OZI; fsdata->fs.copy = (fs_copy) ozi_copy_fsdata; fsdata->fs.destroy = ozi_free_fsdata; + fsdata->fs.convert = NULL; /* Provide defaults via command line defaults */ fsdata->fgcolor = color_to_bbggrr(wptfgcolor); diff --git a/gpsbabel/xmltag.c b/gpsbabel/xmltag.c index 992ec4871..50c4a46ee 100644 --- a/gpsbabel/xmltag.c +++ b/gpsbabel/xmltag.c @@ -96,6 +96,25 @@ void copy_xml_tag( xml_tag **copy, xml_tag *src, xml_tag *parent ) { copy_xml_tag( &(res->child), src->child, res ); } +static void +convert_xml_tag( xml_tag *tag ) { + char **ap = NULL; + + if (tag == NULL) return; + + tag->cdata = cet_convert_string(tag->cdata); + tag->parentcdata = cet_convert_string(tag->parentcdata); + + ap = tag->attributes; + while (*ap) + { + *ap = cet_convert_string(*ap); + ap++; + } + convert_xml_tag(tag->sibling); + convert_xml_tag(tag->child); +} + fs_xml *fs_xml_alloc( long type ); void fs_xml_destroy( void *fs ) { @@ -117,6 +136,12 @@ void fs_xml_copy( void **copy, void *source ) { copy_xml_tag( &(((fs_xml *)(*copy))->tag), src->tag, NULL ); } +void fs_xml_convert( void *fs ) { + fs_xml *xml = (fs_xml *)fs; + if ( xml ) { + convert_xml_tag( xml->tag ); + } +} fs_xml *fs_xml_alloc( long type ) { fs_xml *result = NULL; @@ -125,7 +150,7 @@ fs_xml *fs_xml_alloc( long type ) { result->fs.type = type; result->fs.copy = fs_xml_copy; result->fs.destroy = fs_xml_destroy; + result->fs.convert = fs_xml_convert; return result; } - -- 2.30.2